Skip to content

🧪 [Testing Improvement] Add edge case tests for percentile calculation - #189

Closed
alvin000009238 wants to merge 1 commit into
mainfrom
test-percentile-edge-cases-13288534687710996227
Closed

🧪 [Testing Improvement] Add edge case tests for percentile calculation#189
alvin000009238 wants to merge 1 commit into
mainfrom
test-percentile-edge-cases-13288534687710996227

Conversation

@alvin000009238

Copy link
Copy Markdown
Owner

🎯 What
Added edge case tests for the percentile function in GradeAnalysis.kt which handles percentile info creation given rank and count inputs.

📊 Coverage

  • Testing when inputs are null.
  • Testing negative numbers and zeros for rank and count.
  • Testing limits where rank > count verifying the coercion to 100%.
  • Testing limits for top percentage handling verifying the coercion to 1%.

Result
Improved code coverage and reliability by fully documenting the expected outputs of invalid constraints on percentile ranking logic.


PR created automatically by Jules for task 13288534687710996227 started by @alvin000009238

Co-authored-by: alvin000009238 <107313913+alvin000009238@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings June 17, 2026 14:28

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds unit tests to GradeAnalysisTest.kt to verify the behavior of the percentile function under various edge cases, such as invalid/missing inputs, rank exceeding count, and top rank. The reviewer suggested that the percentile function should return null instead of coercing the value when the rank exceeds the count, as a rank greater than the total count represents an invalid state.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +26 to +29
@Test
fun percentileCoercesToValidRangeWhenRankExceedsCount() {
assertEquals(100, percentile(40.0, 37)?.topPercent)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test asserts that percentile(40.0, 37) returns a valid PercentileInfo with topPercent = 100. However, a rank of 40 in a class of 37 (rank > count) is an invalid state. Allowing this to succeed means the UI might display an invalid rank label like "40/37".

Consider whether percentile should return null when rank > count to prevent displaying invalid data. If so, you can update percentile in GradeAnalysis.kt as follows:

fun percentile(rank: Double?, count: Int?): PercentileInfo? {
    if (rank == null || count == null || count <= 0 || rank > count) return null
    // ...
}

And update this test to assert assertNull instead.

Suggested change
@Test
fun percentileCoercesToValidRangeWhenRankExceedsCount() {
assertEquals(100, percentile(40.0, 37)?.topPercent)
}
@Test
fun percentileReturnsNullWhenRankExceedsCount() {
assertNull(percentile(40.0, 37))
}

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR expands unit test coverage for percentile in GradeAnalysis.kt, documenting expected behavior for invalid inputs and boundary coercion, which helps prevent regressions in rank-to-percentile calculations used in grade analysis.

Changes:

  • Add tests asserting percentile(...) returns null when rank/count are missing or invalid (null, non-positive).
  • Add a boundary test ensuring rank > count coerces topPercent to 100.
  • Add a boundary test ensuring very top ranks don’t round down below 1% (coerces to 1).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@alvin000009238
alvin000009238 deleted the test-percentile-edge-cases-13288534687710996227 branch July 9, 2026 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants